<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<?php
session_start();
if (empty($_SESSION["loginusername"])) {
    Header("Location: firstphp.php");
}
if (!empty($_SESSION["userType"])) {
    $userType = $_SESSION["userType"];
}
?>
<html>
    <head>
        <title>Activity Attendance Recording</title>
        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />
        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery-1.6.min.js"></script>
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery.easyui.min.js"></script>
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery.min.js"></script>
        <script src="http://localhost/Eldercare/jquery/demoad.js"></script>
        <script type='text/javascript'>
            var url;
            $(function getActivityAttendance() {
                $.get('ActivityAttendance/getActAttendance.php', {}, function(data) {
                    $('#tblActivityAttendance').replaceWith($(data));
                });
            });
            function selectedActivity(form)
            {
                var selected_value = form.man.options[form.man.options.selectedIndex].value;
                self.location = 'ActivityAttendance/ddlAct.php?form=' + selected_value;
            }

            /*
             function postValue($name, $alt = '') {
             return isset($_POST[$name]) ? $_POST[$name] : $alt;
             }*/
            function selectAll() {
                if (document.getElementById('cball').checked) {
                    var inputs = document.getElementsByName("cbpa[]");
                    for (var i = 0; i < inputs.length; i++)
                        if (inputs[i].type == "checkbox")
                            inputs[i].checked = true;
                }
                else
                {
                    var inputs = document.getElementsByName("cbpa[]");

                    for (var i = 0; i < inputs.length; i++)
                        if (inputs[i].type == "checkbox")
                            inputs[i].checked = false;
                }

            }
            function selectOne(obj) {
                var cbpen = obj.name;
                var cbpev = obj.id;
                if (document.getElementById(cbpev).checked == false) {
                    var inputs = document.getElementsByName(cbpen);
                    for (var i = 0; i < inputs.length; i++)
                        if (inputs[i].type == "checkbox")
                            inputs[i].checked = false;
                }
                else
                {
                    var inputs = document.getElementsByName(cbpen);
                    for (var i = 0; i < inputs.length; i++)
                        if (inputs[i].type == "checkbox")
                            inputs[i].checked = false;
                    document.getElementById(cbpev).checked = true;
                }
            }
            function perf(obj)
            {
                var pe = obj.id;
                for (i = 1; i <= 5; i++)
                {
                    document.getElementById(i).checked = false;
                }
                document.getElementById(pe).checked = true;
            }
            function form()
            {
                document.getElementById("cbForm").submit();

            }


        </script>
        <style type="text/css">
            body {
                background: #FFFFFF url("images/bg.png") repeat;
                background-attachment:fixed;
            }
            .button 
            {
                background-color:beige;
                cursor:pointer; }

            .btn
            {
                background-color:#FFF5EE;
                cursor:pointer;
            }

        </style>

    </head>
    <body onLoad="document.nricform.barcode.focus();">
        <ul>
            <div class="banner"></div>
            <div id="main">
                <div class="left-wrapper">
                    <div class="logo">
                    </div>
                    <div class="menu-wrapper">
                        <div id='cssmenu' >     
                            <ul>
                                <?php
                                if ($userType == "Therapy Assistant") {
                                    //if TA
                                    echo "<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li class='last'><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			 </ul>
			  </li>
			  <li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
		 <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
   <li class='last'><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
     
			 ";
                                } else if ($userType == "Centre Manager") {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                } else {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/Centres.php'><span>Centres</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Activities.php'><span>Manage Current Activities</span></a></li>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Holidays.php'><span>Holiday</span></a></li>
<li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                }
                                ?>
                            </ul>
                        </div>
                        <div class="clear"></div></div></div>
                <div class="content">
                    <div class="content2">


                        <b style="float:right; margin: 0px 0 0 0">  <?php
                            //session_start();
                            if (!empty($_SESSION["centreName"])) {
                                $Username = $_SESSION["loginusername"];
                                $centreName = $_SESSION["centreName"];
                                echo "Welcome, " . $Username . " ! <br>" . $centreName . " Branch";
                            } else {
                                $Username = $_SESSION["loginusername"];
                                echo "Welcome, " . $Username;
                            }
                            ?>

                            <?php
//session_start();
// set timeout period in seconds
                            $inactive = 7200;
// check to see if $_SESSION['timeout'] is set
                            if (isset($_SESSION["timeout"])) {
                                $session_life = time() - $_SESSION["timeout"];
                                if ($session_life > $inactive) {
                                    session_destroy();
                                    Header("Location: Timeout.php");
                                }
                            }
                            $_SESSION["timeout"] = time();
                            ?>


                            <input type="submit" class="button" value="Logout" onclick="parent.location = 'logout.php'"></b>
                        </p><div class="clear"></div>
                        <h3> Activity Attendance Recording </h3>
                        <br>
                        <form method = "post" name="ddlform" action="">
                            <select name="ddlActivity">
                                <option value="0"selected >Select an Activity</option>
                                <?php
                                mysql_connect("localhost", "root", "");
                                mysql_select_db("eldercaredb");
                                $activityDetail = "SELECT ActivityId, ActivityName FROM activity";
                                $query_result = mysql_query($activityDetail);
                                while ($result = mysql_fetch_assoc($query_result)) {
                                    ?>
                                    <option value="<?php echo $result['ActivityId'] ?>"><?php echo $result['ActivityName'] ?></option>

                                    <?php
                                }
                                ?>
                            </select>
                            <input type="submit" button class = "btn"id="submit" value = 'Submit' name="selectedActivity"/>


                        </form>
                        <?php
                        if (!isset($_POST['selectedActivity']) && empty($_SESSION['first'])) {
                            echo "<font color='red'>Please select an Activity!</font>";
                        } if (isset($_POST['selectedActivity'])) {

                            if ($userType !== "System Admin") {
                                echo"<style='vertical-align:middle;text-align:center'><b>Scan NRIC: </b>
                                &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>Performance: </b>
		<form method = 'post' name='nricform' >
		<input id='barcode'class='tb10'type='text' name='barcode' size='10' maxLength='9'onKeyUp='if(barcode.length==7)makeAttendance()'/>
		<input id = 'ddlActivity' name = 'ddlActivity' type = 'hidden' value = '";
                                echo isset($_POST['selectedActivity']) ? $_POST['ddlActivity'] : '';
                                echo"'/>";
                                echo"&nbsp;
                                1:<input type='checkbox' name='perf[]' value='1' id='1' onClick='perf(this)'/>&nbsp2:
                                <input type='checkbox' name='perf[]' value='2' id='2' onClick='perf(this)'/>&nbsp3:
                                <input type='checkbox' name='perf[]' value='3' id='3' onClick='perf(this)'/>&nbsp4:
                                <input type='checkbox' name='perf[]' value='4' id='4' onClick='perf(this)'/>&nbsp5:
                                <input type='checkbox' name='perf[]' value='5' id='5' onClick='perf(this)'/>
                                <input type='submit' name='btnActSubmit' id='btnActSubmit' value='Submit'/>
                                </form></style><p></p>";


                                echo"</p>";
                            }
                        }
                        ?>


                        <?php
                        if (isset($_POST['btnActSubmit'])) {
                            if (isset($_POST['barcode'])) {
                                if (strlen($_POST['barcode']) != 9) {
                                    echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>Invalid NRIC!</font>";
                                    include_once ("ActivityAttendance/getattendance.php");
                                    echo"<p></p>";
                                } else {
                                    if (isset($_POST['perf'])) {
                                        $string = implode(', ', $_POST['perf']);
                                        if ($string == 1 || $string == 2 || $string == 3 || $string == 4 || $string == 5) {
                                            include_once("ActivityAttendance/makeActAttendance.php");
                                            include_once("ActivityAttendance/getActAttendance.php");
                                            echo"<p></p>";
                                        } else {
                                            echo "<font color='red'>Please enter the NRIC and Performance!</font>";
                                            include_once ("ActivityAttendance/getattendance.php");
                                            echo"<p></p>";
                                        }
                                    }
                                }
                            } else {
                                echo "<font color='red'>Please enter the NRIC and Performance!</font>";
                                include_once ("ActivityAttendance/getattendance.php");
                                echo"<p></p>";
                            }
                        } else if (isset($_POST['selectedActivity'])) {
                            $_SESSION['first'] = 'true';
                            ?> <!--<form method="post" action="window.location.href='ActivityAttendance/submit.php'">
                                                                                            <input type="submit" name="btnSubmit" onClick="call();">
                                                                                        </form>--><?php
                            $_SESSION['SelectedActivity'] = $_POST['ddlActivity'];
                            include_once("ActivityAttendance/getActAttendance.php");
                            echo"<p></p>";
                        } else if (isset($_POST['btnSubmit'])) {
                            $cb = 0;
                            $showAlert = false;
                            if (!empty($_POST['cbpa'])) {
                                foreach ($_POST['cbpa']as $check) {
                                    list($nric, $count) = explode("-", $check, 2);
                                    if (!empty($_POST['cbpe' . $count])) {
                                        $cb++;
                                    } else {
                                        if ($showAlert == true)
                                            echo "<script>alert('Please select all checkboxes')</script>";
                                        $shoAlert = false;
                                    }
                                }
                                if (count($_POST['cbpa']) == $cb) {
                                    echo "<script>form();</script>";
                                    include_once("ActivityAttendance/submit.php");
                                    include_once ("ActivityAttendance/getattendance.php");
                                    echo "<p></p>";
                                } else {
                                    echo "<script>";
                                    echo "alert('Please select all the checkboxes!')";
                                    echo "</script>";
                                    if ($userType !== "System Admin") {
                                        echo"<style='vertical-align:middle;text-align:center'><b>Scan NRIC: </b>
                                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>Performance: </b>
                    <form method = 'post' name='nricform' >
                    <input id='barcode'class='tb10'type='text' name='barcode' size='10' maxLength='9'onKeyUp='if(barcode.length==7)makeAttendance()'/>
                    <input id = 'ddlActivity' name = 'ddlActivity' type = 'hidden' value = '";
                                        echo isset($_POST['selectedActivity']) ? $_POST['ddlActivity'] : '';
                                        echo"'/>";
                                        echo"&nbsp;
                                    1:<input type='checkbox' name='perf[]' value='1' id='1' onClick='perf(this)'/>&nbsp2:
                                    <input type='checkbox' name='perf[]' value='2' id='2' onClick='perf(this)'/>&nbsp3:
                                    <input type='checkbox' name='perf[]' value='3' id='3' onClick='perf(this)'/>&nbsp4:
                                    <input type='checkbox' name='perf[]' value='4' id='4' onClick='perf(this)'/>&nbsp5:
                                    <input type='checkbox' name='perf[]' value='5' id='5' onClick='perf(this)'/>
                                    <input type='submit' name='btnActSubmit' id='btnActSubmit' value='Submit'/>
                                    </form></style><p></p>";


                                        echo"</p>";
                                    }
                                    include_once("ActivityAttendance/getActAttendance.php");
                                    echo"<p></p>";
                                }
                            } else {
                                echo "<script>";
                                echo "alert('Please select all the checkboxes!')";
                                echo "</script>";
                                if ($userType !== "System Admin") {
                                    echo"<style='vertical-align:middle;text-align:center'><b>Scan NRIC: </b>
                                    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>Performance: </b>
                    <form method = 'post' name='nricform' >
                    <input id='barcode'class='tb10'type='text' name='barcode' size='10' maxLength='9'onKeyUp='if(barcode.length==7)makeAttendance()'/>
                    <input id = 'ddlActivity' name = 'ddlActivity' type = 'hidden' value = '";
                                    echo isset($_POST['selectedActivity']) ? $_POST['ddlActivity'] : '';
                                    echo"'/>";
                                    echo"&nbsp;
                                    1:<input type='checkbox' name='perf[]' value='1' id='1' onClick='perf(this)'/>&nbsp2:
                                    <input type='checkbox' name='perf[]' value='2' id='2' onClick='perf(this)'/>&nbsp3:
                                    <input type='checkbox' name='perf[]' value='3' id='3' onClick='perf(this)'/>&nbsp4:
                                    <input type='checkbox' name='perf[]' value='4' id='4' onClick='perf(this)'/>&nbsp5:
                                    <input type='checkbox' name='perf[]' value='5' id='5' onClick='perf(this)'/>
                                    <input type='submit' name='btnActSubmit' id='btnActSubmit' value='Submit'/>
                                    </form></style><p></p>";


                                    echo"</p>";
                                }
                                include_once("ActivityAttendance/getActAttendance.php");
                                echo"<p></p>";
                            }
                        } else {
                            include_once ("ActivityAttendance/getattendance.php");

                            echo"<p></p>";
                            ;
                        }
                        ?></div><div class="clear"></div></div>
            </div></body>
   
</html>